home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / lib-old / packmail.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  133 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. from stat import ST_MTIME
  6.  
  7. def help():
  8.     print 'All fns have a file open for writing as first parameter'
  9.     print 'pack(f, fullname, name): pack fullname as name'
  10.     print 'packsome(f, directory, namelist): selected files from directory'
  11.     print 'packall(f, directory): pack all files from directory'
  12.     print 'packnotolder(f, directory, name): pack all files from directory'
  13.     print '                        that are not older than a file there'
  14.     print 'packtree(f, directory): pack entire directory tree'
  15.  
  16.  
  17. def pack(outfp, file, name):
  18.     fp = open(file, 'r')
  19.     outfp.write('echo ' + name + '\n')
  20.     outfp.write('sed "s/^X//" >"' + name + '" <<"!"\n')
  21.     while None:
  22.         line = fp.readline()
  23.         if not line:
  24.             break
  25.         
  26.         if line[-1:] != '\n':
  27.             line = line + '\n'
  28.         
  29.     outfp.write('!\n')
  30.     fp.close()
  31.  
  32.  
  33. def packsome(outfp, dirname, names):
  34.     for name in names:
  35.         print name
  36.         file = os.path.join(dirname, name)
  37.         pack(outfp, file, name)
  38.     
  39.  
  40.  
  41. def packall(outfp, dirname):
  42.     names = os.listdir(dirname)
  43.     
  44.     try:
  45.         names.remove('.')
  46.     except:
  47.         pass
  48.  
  49.     
  50.     try:
  51.         names.remove('..')
  52.     except:
  53.         pass
  54.  
  55.     names.sort()
  56.     packsome(outfp, dirname, names)
  57.  
  58.  
  59. def packnotolder(outfp, dirname, oldest):
  60.     names = os.listdir(dirname)
  61.     
  62.     try:
  63.         names.remove('.')
  64.     except:
  65.         pass
  66.  
  67.     
  68.     try:
  69.         names.remove('..')
  70.     except:
  71.         pass
  72.  
  73.     oldest = os.path.join(dirname, oldest)
  74.     st = os.stat(oldest)
  75.     mtime = st[ST_MTIME]
  76.     todo = []
  77.     for name in names:
  78.         print name, '...',
  79.         st = os.stat(os.path.join(dirname, name))
  80.         if st[ST_MTIME] >= mtime:
  81.             print 'Yes.'
  82.             todo.append(name)
  83.             continue
  84.         print 'No.'
  85.     
  86.     todo.sort()
  87.     packsome(outfp, dirname, todo)
  88.  
  89.  
  90. def packtree(outfp, dirname):
  91.     print 'packtree', dirname
  92.     outfp.write('mkdir ' + unixfix(dirname) + '\n')
  93.     names = os.listdir(dirname)
  94.     
  95.     try:
  96.         names.remove('.')
  97.     except:
  98.         pass
  99.  
  100.     
  101.     try:
  102.         names.remove('..')
  103.     except:
  104.         pass
  105.  
  106.     subdirs = []
  107.     for name in names:
  108.         fullname = os.path.join(dirname, name)
  109.         if os.path.isdir(fullname):
  110.             subdirs.append(fullname)
  111.             continue
  112.         print 'pack', fullname
  113.         pack(outfp, fullname, unixfix(fullname))
  114.     
  115.     for subdirname in subdirs:
  116.         packtree(outfp, subdirname)
  117.     
  118.  
  119.  
  120. def unixfix(name):
  121.     comps = name.split(os.sep)
  122.     res = ''
  123.     for comp in comps:
  124.         if comp:
  125.             if res:
  126.                 res = res + '/'
  127.             
  128.             res = res + comp
  129.             continue
  130.     
  131.     return res
  132.  
  133.